<?php

namespace app\modules\models;

use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
use Yii;
use yii\helpers\ArrayHelper;
use yii\behaviors\BlameableBehavior;

class Brand extends ActiveRecord
{

    public function behaviors()
    {
        return [
            [
                'class' => BlameableBehavior::className(),
                'createdByAttribute' => 'cuid',
                'updatedByAttribute' => 'uuid',
                'value' => Yii::$app->admin->id,
            ],
            [
                'class'              => TimestampBehavior::className(),
                'createdAtAttribute' => 'createTime',
                'updatedAtAttribute' => 'updateTime',
                'value'              => time(),
            ],
        ];
    }

    public static function tableName()
    {
        return "{{%brand}}";
    }

    public function attributeLabels()
    {
        return [
            'title' => '品牌名称'
        ];
    }

    public function rules()
    {
        return [
            ['title', 'required', 'message' => '品牌名称不能为空'],
            ['createTime', 'safe']
        ];
    }

    public function add($data)
    {
        if ($this->load($data) && $this->save()) {
            return true;
        }
        return false;
    }

    public static function getData()
    {
        $brands = self::find()->all();
        $brands = ArrayHelper::toArray($brands);
        $arr_brands=[];
        foreach ($brands as $brand){
            $arr_brands[$brand['brandid']]=$brand['title'];
        }
        return $arr_brands;
    }


}





